package main

import (
	"log"
	"net/http"

	"todolist/config"
	"todolist/internal/api"
	"todolist/internal/repository"
	"todolist/internal/service"
	"todolist/pkg/database"
)

func main() {
	cfg := config.GetConfig()
	
	db, err := database.Connect(cfg)
	if err != nil {
		log.Fatal(err)
	}
	defer db.Close()

	userRepo := repository.NewUserRepository(db)
	todoRepo := repository.NewTodoRepository(db)

	userService := service.NewUserService(userRepo)
	todoService := service.NewTodoService(todoRepo)

	handler := api.NewHandler(userService, todoService)
	router := api.NewRouter(handler)

	log.Printf("Starting server on :8080")
	log.Fatal(http.ListenAndServe(":8080", router))
}